<%
    /**
     * OperatingFlow(操作流程)js
     *  填写电子表单后下个控件聚焦
     *  created by amon lei 2006-1-4
     */
%>
<script>

    /**
     * 聚焦下一个控件
     * 控件有如下属性：
     *  1. 事件： onkeyup="nextOfFocused(this)" 最后一个可选(往往是类似提交按钮功能的按钮)
     *  2. 控件被聚焦后的js ：afterFocusedJS="" 必须
     *  3. OF的标识控件： of="true" 必须
     */
    function nextOfFocused(obj)
    {
        var keycode = event.keyCode 
        if(keycode == 13)
        {
            focusOther(obj);
        }
    }

    function focusOther(obj)
    {
        var found = false;
        for (i = 0;i < document.all.length;i++) 
        { 
            if(document.all[i] == obj)
            {
//              alert(document.all[i].name);
                found = true;
                continue;
            }
            if(document.all[i].of == "true"
            && found)
            {

                
                try
                {
                    eval(document.all[i].afterFocusedJS);
                }
                catch(err)
                {
                    alert("执行" + document.all[i].name + "js脚本afterFocusedJS(" + document.all[i].afterFocusedJS + ")失败：" + err);
                }
                //              alert(obj.name + " next is: " + document.all[i].name);
                document.all[i].focus();
                return;
            }
            if(i == (document.all.length - 1))
            {
                i = 0;
            }
                 
        }//for 
    }

    // 异常聚焦
    function focus4Ivos()
    {

    <%
        if(request.getAttribute("errMessKeys")!= null)
        {
            Object[] ivos = (Object[])request.getAttribute("errMessKeys");    
    %>
        var ivos = new Array(<%= ivos.length%>);    
    <%
        for(int i = 0; i < ivos.length; i ++)
        {
            %>ivos[<%= i%>] = "<%= ivos[i]%>";<%
        }//for
        if(ivos.length == 0)
        {
            %>return;<%
        }
    %>
        for (i = 0;i < document.all.length;i++) 
        {
            if(document.all[i].of == "true")
            {
                for(j = 0; j < ivos.length; j ++)
                {
                   // alert(document.all[i].name);
                    if(document.all[i].name == ivos[j])
                    {
                        document.all[i].focus();
                        return;
                    }
                }// for
            } // if
        }// for
        <%
        }//if    
        %>
    }

    // 高亮并且聚焦
    function highLightAndFocused(obj)
    {
        try
        {
            for (i = 0;i < document.all.length;i++) 
            {
                if(document.all[i].of == "true" || document.all[i].of == "false")
                {
                    document.all[i].style.backgroundColor = "";
                }
                
            }
        }
        catch(err)
        {
            alert(err);
        }
        obj.style.backgroundColor = "#FEFEE5";
//        alert(obj.name + "高亮");
        obj.focus();
    }

    function initOf()
    {
        for (i = 0;i < document.all.length;i++) 
        {
            var ob = document.all[i];
            if(ob.of == "true")
            {
                
                var oldFocusFunc = ob.onfocus;
	            ob.onfocus = function anonymous() {highLightAndFocused(this);if(oldFocusFunc != null ) oldFocusFunc();};
                
            }
        }
    }

</script>
